package cn.swust.classdemo;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Test;

import junit.framework.Assert;

public class AddTwoFunTest01 {

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testAddThree() {
		AddTwoFun testobj
		 = mock(AddTwoFun.class);		
		int a = 50;
		int b = 60;
		int c = 30;
		int exp = 140;
		when(testobj.add(50, 60)).thenReturn(110);
		when(testobj.addThree(50, 60, 30)).thenCallRealMethod();
		int act = testobj.addThree(a, b, c);
		Assert.assertEquals("错误", exp, act);
	}
	
	@Test
	public void testMock() {
		MockDemo testobj = new MockDemo();		
		AddTwoFun mockobj
		 = mock(AddTwoFun.class);
		testobj.addTwo = mockobj;		
		int a = 50;
		int b = 60;
		int c = 30;
		int exp = 140;
		when(mockobj.add(50, 60)).thenReturn(110);
		when(mockobj.add(110, 30)).thenReturn(140);
		when(mockobj.add(20, 30)).thenCallRealMethod();
		int act = testobj.add(a, b, c);
		Assert.assertEquals("错误", exp, act);
	}

}
